﻿/**
	 * 公共弹出提示信息
	 * @param title_name
	 * @param content_value
	 * @return
	 */
	function showCfmMsg(title_name,content_value){
		seajs.use('common/dialog/src/js/dialog_ec',
			function(dialog) {
				dialog.alert({
					type:"alert",
					title:title_name,
					confirm:getLanMsgs("0ec22180-100015"),
					content:content_value
				});
			});
	}

	/**
	 * 公共弹出提示信息
	 * @param title_name
	 * @param content_value
	 * @return
	 */
	function showConfirmDialog(option){
		seajs.use('common/dialog/src/js/dialog_ec',
			function(dialog) {
				dialog.confirm(option);
			});
	}

	function showsfmMsg(title_name,confirmbettn,content_value){
		seajs.use('common/dialog/src/js/dialog_ec',
			function(dialog) {
				dialog.alert({
					type:"alert",
					title:title_name,
					confirm:confirmbettn,
					content:content_value
				});
			});
	}
	
	//表单提交之前处理一下性别字段,将各个组的性别字段的值赋值给gender的text里
	function dealWithGenderProperty(){
		$("[name='gender']").each(function(){
			var id = $(this).attr("id");
			var value = $("input[name='"+id+"']:checked").val();  
			$(this).val(value);
		});
	}

	//添加港华必填的资料类型
	function addRequiredDocTypeByOrg() {
		var myts = new Date();
		var formStr = $('#doctype_filter').serialize();
		var pk_org = $("#vendorOrg").val();
		var pk_group = $("#vendorGroup").val();
		jQuery.ajax( {
			type : "GET",
			async : false,
			url : ebvp_context + "/register/getRequiredDocType?myts="+myts+"&pk_group="+pk_group+"&pk_org="+pk_org,
			dataType : "text",
			data : "&" + formStr,
			success : function(result) {
				if (result != null && result != "[]") {
					var arr = eval(result);
					for (var loop = 0; loop < arr.length; loop++) {
						var newrow = $("#reqdoctype_tpl").find(".idItems").clone();
						var pk = arr[loop].pk_defdoc;
						var name = arr[loop].name;
						$(newrow.find("[name='finfotype']")[0]).val(pk);
						$(newrow.find("[name='finfotypeName']")[0]).val(name);
						$(newrow.find("[name='addDocTypeAttachment']")[0]).attr("id", "addDocTypeAttachment_" + pk);
						newrow.insertBefore($("#addDocType"));
					}
				}
			}
	});
	}
	
var InfoMaintain = function() {
	
	// 上传Logo
	$(".btn_attach_Logo").bind("click", function() {
		var url = ebvp_context + "/sourcingcoll/FileUpload_new.jsp";
		url = url + "?" + "uploadMode=7";
		url = url + "&" + "pkReleaseFileB=" + $("#pk_supinfocheck_h").val();
		url = url + "&" + "isNeedAddRow=Y";
		url = url + "&" + "type=UPLOAD_LOGO";
		url = url + "&" + "id=UPLOAD_LOGO";
		var iTop = (window.screen.availHeight-30-330)/2;
		var iLeft = (window.screen.availWidth-10-620)/2;
		window.open(url,'' ,'width=620,height=330,location=no'+',top='+iTop+',left='+iLeft);
	});

	// 添加联系人信息
	var addContactFunc = function() {
		$("#addContact")
				.bind(
						'click',
						function() {
							var newContact = null;
							//如果原来没有联系人，从联系人模板新增
							//if($(this).parents("#complateContactInfo").find("[identifier='contactList']").length == 0){
							//	newContact = $("#contract_tpl").find("[identifier='contactList']").clone()
							//		.attr("id", "contactGroup_1").insertBefore($("#addContact").parents(".addcontactdiv"));
							//	newContact.find(".form_title:first").html(getLanMsgs("0ec22180-100005")+1);
							//}else{ //如果原来有联系人，则复制联系人行来新建联系人
								var prevContact = $(this).parents(
								"#complateContactInfo").find(
								"[identifier='contactList']").last();
								var idx = parseInt(prevContact.attr("id")
										.split("_")[1]) + 1;
								var newContact = prevContact.clone();
								
								newContact.find(".error").remove(); //不要把上一行的报错复制过来
								
								// 删除UITipinside生成的多余标签
								newContact.find('input').parent('label').find('.ui-cleaner, .clear, .revert').remove();
								newContact.insertAfter(
										prevContact).attr( {
											'id' : "contactGroup_" + idx
										});
										//.hide().slideDown();
								newContact.find(".form_title:first").html(getLanMsgs("0ec22180-100005")+idx);
							//}
							//var iddd = Math
							//		.floor(Math.random() * 10000000000000000000);
							$(newContact.find("[name='linkman']")[0]).attr(
									"id", "linkman" + idx).val("");
							$(newContact.find("[name='mobile']")[0]).attr("id",
									"mobile" + idx).val("");
							$(newContact.find("[name='tel_reg']")[0]).attr(
									"id", "tel_reg" + idx).val("");
							$(newContact.find("[name='tel_phone']")[0]).attr(
									"id", "tel_phone" + idx).val("");
							$(newContact.find("[name='tel_ext']")[0]).attr(
									"id", "tel_ext" + idx).val("");
							$(newContact.find("[name='email']")[0]).attr("id",
									"email" + idx).val("");
							$(newContact.find("[name='position']")[0]).attr("id",
									"position" + idx).val("");
							//性别字段
							$(newContact.find("[name='gender']")[0]).attr("id",
									"gender_" + idx).val("");
							$(newContact.find("[name='gender']")[0]).prev("span").prev("input").attr("name", "gender_" + idx);
							$(newContact.find("[name='gender']")[0]).prev("span").prev("input").prev("span").prev("input").attr("name", "gender_" + idx);
							
							// 增加必输项提示控制
							$(newContact.find("[name='linkman']")[0]).UITipInside({required:true});
							$(newContact.find("[name='mobile']")[0]).UITipInside({required:true});
							$(newContact.find("[name='tel_reg']")[0]).UITipInside({required:true});
							$(newContact.find("[name='tel_phone']")[0]).UITipInside({required:true});
							$(newContact.find("[name='email']")[0]).UITipInside({required:true});
							
							return false;
						});
	}

	
	// 添加银行帐号
	var addBankAccountFunc = function() {
		$("#addBankAccount")
				.bind(
						'click',
						function() {
							var records = $(this).parent().prev("table").find(
									"tbody").find("tr");

							// 初始化币种
							var curryObj = $("<select></select>").attr("name",
									"pkCurrency");
							var myts = new Date();
							jQuery
									.ajax( {
										type : "GET",
										async : false,
										url : ebvp_context
												+ "/register/qryCurrtypeVOList?myts="
												+ myts,
										dataType : "text",
										success : function(result) {
											if (result != null) {
												var arr = eval(result);
												for ( var loop = 0; loop < arr.length; loop++) {
													var obj = arr[loop];
													var optObj = $(
															"<option></option>")
															.val(
																	obj.pk_currtype)
															.text(obj.name);
													if (obj.code == "CNY") {
														optObj.attr("selected",
																true);
													}
													curryObj.append(optObj);
												}
											}
										}
									})
							var curryStr = "<select name=\"pkCurrency\" class=\"w_66px\"> "
									+ curryObj.html() + "</select>";

							// 初始化银行类别
							var bankTypeObj = $("<select></select>").attr(
									"name", "bankTypeId");
							var myts1 = new Date();
							jQuery
									.ajax( {
										type : "GET",
										async : false,
										url : ebvp_context
												+ "/register/qryBankTypeDocList?myts="
												+ myts1,
										dataType : "text",
										success : function(result) {
											if (result != null) {
												var arr = eval(result);
												for ( var loop = 0; loop < arr.length; loop++) {
													var obj = arr[loop];
													var optObj = $(
															"<option></option>")
															.val(
																	obj.pk_banktype)
															.text(obj.name);
													if (loop == 0) {
														optObj.attr("selected",
																true);
													}
													bankTypeObj.append(optObj);
												}
											}
										}
									})
							var bankTypeStr = "<select name=\"bankTypeId\" class=\"w_128px\">"
									+ bankTypeObj.html() + "</select>";

							var newRecordss = "<tr>"
									+ "<td><div class='float_left'><div class='form_row'><div class='form_title w_100px'>"
									+ getLanMsgs("0ec22180-100043")
									+ "</div><div class='form_field'><label><input name='supaccount' value='' class='textfield pd_5x2px w_128px required' /></label></div></div><div class='form_row'><div class='form_title w_100px'>"
									+ getLanMsgs("0ec22180-100088")
									+ "</div><div class='form_field'><label><input name='accountname' value='' class='textfield pd_5x2px w_128px required' /></label></div></div></div></td>"
									+ "<td><div class='float_left'><div class='form_row'><div class='form_title w_120px'>"
									+ getLanMsgs("0ec22180-100089")
									+ "</div><div class='form_field'><label title='bankTypeId'>"
									+ bankTypeStr
									+ "</label></div></div><div class='form_row'><div class='form_title w_120px'>"
									+ getLanMsgs("0ec22180-100090")
									+ "</div><div class='form_field'><label><input name='bankDocName' value='' class='textfield pd_5x2px w_128px required' ><img name='refbtn' src='/ebvp/commonres/common/frame/src/img/refer_file_press.png' height='18px' width='18px'  style='margin-top:6px'/><input name='pkBankDoc' value='' type='hidden' ></label></div></div></div></td>"
									+ "<td><div class='form_row'><div class='form_title w_50px'>"
									+ getLanMsgs("0ec22180-100091")
									+ "</div><div class='form_field'><label>"
									+ curryStr
									+ "</label><input type='hidden' name='pk_supbankacc' value='' /><input type='hidden' id='src_bankbas<%=random %>' name='src_bankbas' value='' ></input></div></div></td>"
									+ "<td class='last_column'><a class='btn_delete mrg_0x25px deletebank hand'></a></td>"
									+ "</tr>";
							var newRecord = $(newRecordss);
							$("#complateBankAccount").find("tbody").append(
									newRecord);
							var idx = records.length + 1;
							newRecord.find(".first_column").html(idx);

							// 初始化银行类别 和 币种
							newRecord.find("[title='bankTypeId']").html(
									bankTypeStr);
							newRecord.find("[title='currencyId']").html(
									curryStr);

							$(newRecord.find(".required")).UITipInside( {
								'required' : true
							});

							var iddd = Math
									.floor(Math.random() * 10000000000000000000);
							$(newRecord.find("[name='supaccount']")[0]).attr(
									"id", "supaccount" + iddd);
							$(newRecord.find("[name='accountname']")[0]).attr(
									"id", "accountname" + iddd);
							$(newRecord.find("[name='bankDocName']")[0]).attr(
									"id", "bankDocName" + iddd);
						});
	}

	// 经营场所面积
	$("#bizarea")
			.live("blur",function() {
				subReduNum($("#bizarea")[0], 2);
			}
	);

	// 注册资本
	$("#regfound")
			.bind(
					"blur",
					function() {
						$("#complateBaseInfo").find("[for='regfound']").remove();
						
						var regFoundVal = $("#regfound").val();
						if(regFoundVal == null ||regFoundVal == ""){
							return ;
						}
						var regFounfValAfterFormat = formatMoney(regFoundVal,2);
						$("#regfound").val(regFounfValAfterFormat);
						
						var val = $("#regfound").val();
						if (val != null && val != "") {
							if (val.indexOf(".") == -1) { // 不包含小数点
								var commaCount = getCount(val, ",");
								if (val.length-commaCount > 11) {
									var errMsg = getLanMsgs("0ec22180-100231");
									var errLabel = $("<img></img>").attr("for", "regfound")
											.attr("src",
													"/ebvp/commonres/common/frame/src/img/validate_error.png")
										    .addClass("error")
											.attr("title", errMsg).attr(
													"style",
													"position:absolute; left:178px");
									errLabel.insertAfter($("#regfound"));
								}
							} else {
								var errMsg = getLanMsgs("0ec22180-100231");
								var valArray = val.split(".");
								var intPart = valArray[0];
								var dotPart = valArray[1];
								var commaCount = getCount(val, ",");
								if (intPart.length - commaCount > 11 ) {
									var errLabel = $("<img></img>").attr("for", "regfound")
											.attr("src",
													"/ebvp/commonres/common/frame/src/img/validate_error.png")
											.addClass("error")
											.attr("title", errMsg).attr(
													"style",
													"position:absolute; left:178px");
									errLabel.insertAfter($("#regfound"));
								}
							}
						}
	});
	

	this.init = function() {

		if (browsepage != "true") {
			if (bGh2Version) {
				$("#complateBaseInfo input, #complateContactInfo input, #complateBankAccount input, #builddate, #complateOrder input")
						.not("#supsimname, #bizarea, #employeenum,.tel_ext, [name='gender'], [name='position'], #url, #corpFaxExt, .supaccount, .accountname, .bankDocName, [name='prod_filter'], #org_filter")
						.UITipInside( {
							'required' : true
						});
				$("#supsimname, #bizarea, #employeenum,.tel_ext, [name='gender'], [name='position'], #url, #attachment input, #complateManagement input, #complateManagement textarea, #corpFaxExt, .supaccount, .accountname")
						.UITipInside();
			} else {
				$("#complateBaseInfo input, #complateContactInfo input, #complateBankAccount input, #builddate")
						.not("#supenname, #supsimname, #bizarea, #employeenum,.tel_ext, [name='gender'], [name='position'], #url, #corpFaxReg, #corpFaxNum, #corpFaxExt, .supaccount, .accountname, .bankDocName, [name='prod_filter'], #org_filter")
						.UITipInside( {
							'required' : true
						});
				$("#supenname, #supsimname, #bizarea, #employeenum,.tel_ext, [name='gender'], [name='position'], #url, #attachment input, #complateManagement input, #complateManagement textarea, #corpFaxReg, #corpFaxNum, #corpFaxExt, .supaccount, .accountname")
						.UITipInside();
			}
		}

		addContactFunc();

		addBankAccountFunc();
		
		//delete QA and Doc type attachments
		$("body").delegate(".btn_delete_attach", "click", function() {
			var thisObj = $(this);
			var option = {
				title : getLanMsgs("0ec22180-100163"),
				content : getLanMsgs("0ec22180-100187"),
				confirm : function() {
					var wholepath = getWholePath(thisObj);
					var result = deleteAttachmentsInDB(wholepath);
					if(result == "success"){
						thisObj.parent().prev(".attachment_list").remove();
						thisObj.parent().remove();
					}
					if(result == "fail"){
						var filename = thisObj.parent().prev().find(".attach_filename").text().replace(/[\n\t]/g,"");
						alert("资质："+filename+" 已被引用，不能删除！");
					}
					return true;
				}
			}
			showConfirmDialog(option);
		});
		
		function deleteAttachmentsInDB(wholefilepath){
			var myts = new Date();
			var msg = "";
			jQuery.ajax( {
				type : "GET",
				async : false,
				url : ebvp_context + "/register/deleteAttach?attachpath="
						+ wholefilepath + "&myts=" + myts,
				dataType : "text",
				success : function(result) {
					msg = result;
				},
				error:function(result){
					msg = result;
				}
			});
			return msg;
		}
		
		function getWholePath(delObj){
			var filepath = "";
			if(delObj.parents(".attachment").prev().find("[name='filepath']").length > 0 ){            //资质的
				filepath = $(delObj.parents(".attachment").prev().find("[name='filepath']")[0]).val();
			}else if(delObj.parents(".attachment").prev().find("[name='docfilepath']").length > 0){    //资料类型的
				filepath = $(delObj.parents(".attachment").prev().find("[name='docfilepath']")[0]).val();
			}
			//var filename = delObj.parent().prev().find(".attach_filename").text();
			//filename = filename.substring(0, filename.indexOf("(")); 
			//filename = filename.replace(/[\n\t]/g,"");
			//return escape(encodeURIComponent(filepath + "/" + filename));
			var filename = delObj.parent().prev().find("input[name='fileAlias']").val();
			return escape(encodeURIComponent(filename));
		}

		//Upload QA Attachments
		$("body")
				.delegate(
						"[name='addAttachment']",
						"click",
						function() {
							var pk_qa = $(
									$(this).parents(".idItems").find(
											"[name='pk_qacode']")[0]).val();
							var url = ebvp_context
									+ "/sourcingcoll/FileUpload_new.jsp";
							var pkH = null;
							//author:gaotg 
							//修补资质附件上传原有资质附件丢失的bug
							//如果当前资质已经存在资质附件，则pkH取当前的资质对应的pkH
							var filePath = $(
									$(this).parents(".idItems").find(
											"[name='filepath']")[0]).val();
							if(filePath != null && filePath != ""){
								pkH = filePath.substring(0, filePath.indexOf("/"));
							}else{
								pkH = $("#pk_supinfocheck_h").val();
							}
							if(pkH == null || pkH == "" || pkH == "uapbd"){
								pkH = randomPk;  //随机生成20位数字
							}
							
							url = url + "?" + "uploadMode=7";
							url = url + "&" + "pkReleaseFileB=" + pk_qa;
							url = url + "&" + "pkSupcheckH=" + pkH;
							url = url + "&" + "isNeedAddRow=Y";
							url = url + "&" + "id=" + $(this).attr("id");
							url = url + "&" + "type=UPLOAD_QA_ATTACH";
							var iTop = (window.screen.availHeight-30-330)/2;
							var iLeft = (window.screen.availWidth-10-620)/2;
							window.open(url,'' ,'width=620,height=330,location=no'+',top='+iTop+',left='+iLeft);
						});
		//Upload Doctype Attachments
		$("body")
			.delegate(
				"[name='addDocTypeAttachment']",
				"click",
				function() {
					var pk_doctype = $(
							$(this).parents(".idItems").find(
									"[name='finfotype']")[0]).val();
					var url = ebvp_context
							+ "/sourcingcoll/FileUpload_new.jsp";
					var pkH = null;
					//author:gaotg 
					//修补资质附件上传原有资质附件丢失的bug
					//如果当前资质已经存在资质附件，则pkH取当前的资质对应的pkH
					var filePath = $(
							$(this).parents(".idItems").find(
									"[name='docfilepath']")[0]).val();
					if(filePath != null && filePath != ""){
						pkH = filePath.substring(0, filePath.indexOf("/"));
					}else{
						pkH = $("#pk_supinfocheck_h").val();
					}
					if(pkH == null || pkH == ""){
						pkH = randomPk;  //随机生成20位数字
					}
					url = url + "?" + "uploadMode=7";
					url = url + "&" + "pkReleaseFileB=" + pk_doctype;
					url = url + "&" + "pkSupcheckH=" + pkH;
					url = url + "&" + "isNeedAddRow=Y";
					url = url + "&" + "id=" + $(this).attr("id");
					url = url + "&" + "type=UPLOAD_DOC_TYPE";
					var iTop = (window.screen.availHeight-30-330)/2;
					var iLeft = (window.screen.availWidth-10-620)/2;
					window.open(url,'' ,'width=620,height=330,location=no'+',top='+iTop+',left='+iLeft);
		});
		
		// 删除银行帐号
		$("body").delegate(".deletebank", "click", function() {

			var thisObj = $(this);
			var option = {
				title : getLanMsgs("0ec22180-100163"),
				content : getLanMsgs("0ec22180-100188"),
				confirm : function() {
					thisObj.parents("tr").remove();
					return true;
				}
			}
			showConfirmDialog(option);

		});
		// 删除产品
		$("body").delegate(".deleteprod", "click", function() {

			var thisObj = $(this);
			var option = {
				title : getLanMsgs("0ec22180-100163"),
				content : getLanMsgs("0ec22180-100188"),
				confirm : function() {
					thisObj.parents("tr").remove();
					return true;
				}
			}
			showConfirmDialog(option);

		});
		$("body").delegate(".btn_delete_qa", "click", function() {
			var thisObj = $(this);
			var option = {
				title : getLanMsgs("0ec22180-100163"),
				content : getLanMsgs("0ec22180-100188"),
				confirm : function() {
					thisObj.parents(".idItems").remove();
					return true;
				}
			}
			showConfirmDialog(option);
		});

		$("body").delegate(
				".btn_delete_contact_1",
				"click",
				function() {
					if ($("#complateContactInfo").find(
							"[identifier='contactList']").size() == 1) {
						showCfmMsg(getLanMsgs("0ec22180-100163"),
								getLanMsgs("0ec22180-100189"));
						return;
					};

					var thisObj = $(this);
					var option = {
						title : getLanMsgs("0ec22180-100163"),
						content : getLanMsgs("0ec22180-100190"),
						confirm : function() {
							thisObj.parents("[identifier='contactList']")
									.remove();
							return true;
						}
					};
					showConfirmDialog(option);
		});
		
		//这里校验联系人字段
		$("body").delegate("[name='linkman']", "blur", function(){
			var requiredStr = getLanMsgs("0ec22180-100167"); //必填
			var linkmanInRow = $(this);
			linkmanInRow.next("[for='linkman']").remove();
			var linkmanVal = linkmanInRow.val();
			if(linkmanVal == null || linkmanVal == ""){
				var errLabel = $("<img></img>").attr("for", "linkman")
				    .attr("src",
						"/ebvp/commonres/common/frame/src/img/validate_error.png")
						.addClass("error")
				        .attr("title", requiredStr)
				        .attr("style","position:absolute; left:178px; z-index:1000;");
				errLabel.insertAfter(linkmanInRow);
			}
		});
		
		//这里校验联系人信息中的固定电话区号
		$("body").delegate("[name='tel_reg']", "blur", function(){
			var requiredStr = getLanMsgs("0ec22180-100167"); //必填
			var formatStr = getLanMsgs("0ec22180-100169");   //格式错误
			var tel_regInRow = $(this);
			tel_regInRow.next("[for='tel_reg']").remove();
			var tel_regVal = tel_regInRow.val();
			if(tel_regVal == null || tel_regVal == ""){
				var errLabel = $("<img></img>").attr("for", "tel_reg")
				    .attr("src",
						"/ebvp/commonres/common/frame/src/img/validate_error.png")
						.addClass("error")
				        .attr("title", requiredStr)
				        .attr("style","position:absolute; left:34px; z-index:1000;");
				errLabel.insertAfter(tel_regInRow);
			}else if(!checkNum(tel_regVal)){
				var errLabel = $("<img></img>").attr("for", "tel_reg")
			        .attr("src",
					      "/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
			        .attr("title", formatStr)
			        .attr("style","position:absolute; left:34px; z-index:1000;");
			    errLabel.insertAfter(tel_regInRow);
			}
		});
		
		//这里校验联系人信息中的固定电话号码
		$("body").delegate("[name='tel_phone']", "blur", function(){
			var requiredStr = getLanMsgs("0ec22180-100167"); //必填
			var formatStr = getLanMsgs("0ec22180-100169");   //格式错误
			var telPhoneInRow = $(this);
			telPhoneInRow.next("[for='tel_phone']").remove();
			var telPhoneVal = telPhoneInRow.val();
			if(telPhoneVal == null || telPhoneVal == ""){
				var errLabel = $("<img></img>").attr("for", "tel_phone")
				    .attr("src",
						"/ebvp/commonres/common/frame/src/img/validate_error.png")
						.addClass("error")
				        .attr("title", requiredStr)
				        .attr("style","position:absolute; left:76px; z-index:1000;");
				errLabel.insertAfter(telPhoneInRow);
			}else if(!checkNum(telPhoneVal)){
				var errLabel = $("<img></img>").attr("for", "tel_phone")
			        .attr("src",
					      "/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
			        .attr("title", formatStr)
			        .attr("style","position:absolute; left:76px; z-index:1000;");
			    errLabel.insertAfter(telPhoneInRow);
			}
		});
		
		//这里校验联系人信息中的固定电话分机号
		$("body").delegate("[name='tel_ext']", "blur", function(){
			var formatStr = getLanMsgs("0ec22180-100169");   //格式错误
			var telExtInRow = $(this);
			telExtInRow.next("[for='tel_ext']").remove();
			var telExtVal = telExtInRow.val();
			if(telExtVal!=null && telExtVal !="" && !checkNum(telExtVal)){
				var errLabel = $("<img></img>").attr("for", "tel_ext")
			        .attr("src",
					      "/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
			        .attr("title", formatStr);
			        //.attr("style","position:absolute; left:178px; z-index:1000;");
			    errLabel.insertAfter(telExtInRow);
			}
		});
		
		//这里校验联系人信息中的手机号
		$("body").delegate("[name='mobile']", "blur", function(){
			var requiredStr = getLanMsgs("0ec22180-100167"); //必填
			var formatStr = getLanMsgs("0ec22180-100169");   //格式错误
			var mobileInRow = $(this);
			mobileInRow.next("[for='mobile']").remove();
			var mobileVal = mobileInRow.val();
			if(mobileVal == null || mobileVal == ""){
				var errLabel = $("<img></img>").attr("for", "mobile")
				    .attr("src",
						"/ebvp/commonres/common/frame/src/img/validate_error.png")
						.addClass("error")
				        .attr("title", requiredStr)
				        .attr("style","position:absolute; left:178px");
				errLabel.insertAfter(mobileInRow);
			}else if(!checkNum(mobileVal)){
				var errLabel = $("<img></img>").attr("for", "mobile")
			        .attr("src",
					      "/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
			        .attr("title", formatStr)
			        .attr("style","position:absolute; left:178px");
			    errLabel.insertAfter(mobileInRow);
			}
		});
		
		//联系人的电子邮箱 
		$("body").delegate("[name='email']", "blur", function(){
			$(this).next("[for='email']").remove();
			if($(this).val()==null||$(this).val()==""){
				var errorImg = $("<img></img>")
				.attr("for", "email")
				.attr("title", getLanMsgs("0ec22180-100167"))
				.attr("src","/ebvp/commonres/common/frame/src/img/validate_error.png")
				.addClass("error")
				.attr("style", "position:absolute; left:178px;");
				errorImg.insertAfter($(this));
			}else if(!checkEmail($(this).val())){
				var errorImg = $("<img></img>")
					.attr("for", "email")
					.attr("title", getLanMsgs("0ec22180-100171"))
					.attr("src","/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
					.attr("style", "position:absolute; left:178px;");
				errorImg.insertAfter($(this));
			}
		});
		//公司的电子邮箱
		$("body").delegate("#corpEmail", "blur", function(){
			$("body").find("[for='corpEmail']").remove();
			if(!checkEmail($(this).val())){
				var errorImg = $("<img></img>")
					.attr("for", "corpEmail")
					.attr("title", getLanMsgs("0ec22180-100171"))
					.attr("src","/ebvp/commonres/common/frame/src/img/validate_error.png")
					.addClass("error")
					.attr("style", "position:absolute; left:180px; top:1px");
				errorImg.insertAfter($(this));
			}
		});
	};
};

/**
 * 
 * 
 */
$(function() {
	var infoMaintain = new InfoMaintain();
	infoMaintain.init();
});

// 经济类型
var initEctype = function() {
	jQuery.ajax( {
		type : "GET",
		async : false,
		url : ebvp_context + "/register/initlist?code=" + "SYS004_0xx",
		dataType : "text",
		success : function(result) {
			if (result != "[]") {
				var arr = eval(result);
				var sel = $("<select></select>").attr("name", "ectype");
				for ( var loop = 0; loop < arr.length; loop++) {
					var obj = arr[loop];
					var option = $("<option></option>").val(obj.pk_defdoc)
							.text(obj.name);
					if (ectypeValue == obj.pk_defdoc) {
						option.attr("selected", "selected");
					}
					sel.append(option);
				}
				sel.addClass("w_178px");
				$("[title='ectype']").append(sel);
			}
		}
	})
}

// 银行类别bankTypeSelect
var initBankTypeSelect = function(labelId, bankTypeId) {
	var myts1 = new Date();
	jQuery.ajax( {
		type : "GET",
		async : false,
		url : ebvp_context + "/register/qryBankTypeDocList?myts=" + myts1,
		dataType : "text",
		success : function(result) {
			if (result != null) {
				var arr = eval(result);
				var sel = $("<select></select>").attr("name", "bankTypeId");
				for ( var loop = 0; loop < arr.length; loop++) {
					var obj = arr[loop];
					var option = $("<option></option>").val(obj.pk_banktype)
							.text(obj.name);
					if (bankTypeId == obj.pk_banktype) {
						option.attr("selected", "selected");
					}
					sel.append(option);
				}
				sel.addClass("w_128px");
				$("#" + labelId).append(sel);
			}
		}
	})
}

// 币种currtypeSelect
var initCurrtypeSelect = function(currtypeLabelId, pkCurrency) {
	var myts = new Date();
	jQuery.ajax( {
		type : "GET",
		async : false,
		url : ebvp_context + "/register/qryCurrtypeVOList?myts=" + myts,
		dataType : "text",
		success : function(result) {
			if (result != null) {
				var arr = eval(result);
				var sel = $("<select></select>").attr("name", "pkCurrency");
				for ( var loop = 0; loop < arr.length; loop++) {
					var obj = arr[loop];
					var option = $("<option></option>").val(obj.pk_currtype)
							.text(obj.name);
					if (pkCurrency == obj.pk_currtype) {
						option.attr("selected", "selected");
					}
					sel.append(option);
				}
				sel.addClass("w_66px");
				$("#" + currtypeLabelId).append(sel);
			}
		}
	})
}
// 资质qaTypeSelect
var initQaTypeSelect = function(qaLabelId, qaPk, pkGroup, pkOrg) {
	var myts = new Date();
	jQuery.ajax( {
		type : "GET",
		async : false,
		url : ebvp_context + "/register/qryLeafQaTypeVO?pk_group=" + pkGroup
				+ "&pk_org=" + pkOrg + "&myts=" + myts,
		dataType : "text",
		success : function(result) {
			if (result != "[]") {
				var arr = eval(result);
				var sel = $("<select></select>").attr("name", "pk_qacode");
				for ( var loop = 0; loop < arr.length; loop++) {
					var obj = arr[loop];
					var option = $("<option></option>").val(obj.pk_qualifitype)
							.text(obj.qualifitype_name);
					if (qaPk == obj.pk_qualifitype) {
						option.attr("selected", "selected");
					}
					sel.append(option);
				}
				sel.addClass("w_485px");
				$("#" + qaLabelId).append(sel);
			}
		}
	})

}

function setVal(dateObj) {
	if (dateObj.val() == null || dateObj.val() == "") {
		dateObj.val("*").attr("style", "color:red; width:172px");
	} else {
		if (dateObj.val() == "*") {
			dateObj.attr("style", "color:red; width:172px")
		} else {
			dateObj.attr("style", "color:black; width:172px")
		}
	}
}
// 日期发生变更时，校验生效日期和失效日期的大小
window.onDatePickerClose = function(id) {
	setVal($(id));
}
// 选择日期时发生的事件
window.onDatePickerSelect = function(obj) {
	setVal($(obj));
}

function goTo(obj) {
	window.location.hash = "#" + $(obj).attr("targetid");
}

//获得字符串的字节数
function getBytesCount(str){
	if(!str){
		return 0;
	}else{
		return (str.length + str.replace(/[\u0000-\u00ff]/g, "").length);
	}
}
